﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Actuals.CoreDomain;
using Actuals.CoreDomain.Data;

namespace Actuals.Data
{
    public class DalBASubTask : Dal<IBASubTask, BASubTask>, IDalBASubTask
    {
         private readonly IDalManager _manager;
        private static readonly IDalBASubTask _instance = new DalBASubTask();
        private const string SP_GET_BA_SUB_TASKS = "usp_GetBASubTasks";
        private const string SP_GET_BA_SUB_TASK = "usp_GetBASubTask";
       

        public static IDalBASubTask Instance
        {
            get { return _instance; }
        }

        public DalBASubTask()
        {
            _manager = new DalManager();
        }

        public DalBASubTask(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(IBASubTask obj, DataRow row)
        {
          
            obj.TaskId = _manager.GetValue<int>(row, "TaskId");
            obj.TaskDescription = _manager.GetValue<string>(row, "TaskDescription");

        }
        public IBASubTask GetBASubTask(int taskId)
        {
            _manager.StoredProcedureName = SP_GET_BA_SUB_TASK;
            _manager.AddInParameter("@TaskId", DbType.Int32 , taskId);

            IBASubTask baSubTask = new BASubTask();
            Convert(baSubTask, _manager.ExecuteDataSet());


            return baSubTask;
        }

        public IList<IBASubTask> GetBASubTasks()
        {
            _manager.StoredProcedureName = SP_GET_BA_SUB_TASKS;
            List<IBASubTask> baSubTasks = new List<IBASubTask>();
            foreach (IBASubTask baSubTask in ConvertAll(_manager.ExecuteDataSet()))
                baSubTasks.Add(baSubTask);

            return baSubTasks;
        }

    }
}
